Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ObjUtil = require("ObjUtil");
var def_VIVO_NativeAdMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.NativeAds = new Map();
    this.adMessage = new Map();
    this.adNodeList = new Map();
    this.isDestroy = true;
    this.isError = false;
    this.nativeShowList = new Map();
  }
  return babel_createClass(_ctor, [{
    key: "Init",
    value: function Init(e) {
      this.NativeID = e;
    }
  }, {
    key: "getMsg",
    value: function getMsg(e) {
      return this.adMessage.get(e);
    }
  }, {
    key: "addNode",
    value: function addNode(e, t) {
      var n = this.adNodeList.get(e);
      if (n) {
        -1 == n.indexOf(t) && n.push(t);
      } else {
        this.adNodeList.set(e, [t]);
      }
    }
  }, {
    key: "sendMsg",
    value: function sendMsg(e, t) {
      var n = this.adNodeList.get(e);
      console.log("发送消息", n);
      if (n) {
        for (var _o133 = 0; _o133 < n.length; _o133++) {
          if (cc.isValid(n[_o133], true)) {
            n[_o133].getComponent("ComNativeView").init(t);
          } else {
            n.splice(_o133, 1);
            _o133--;
          }
        }
      }
    }
  }, {
    key: "Create",
    value: function Create(e, t) {
      var _this148 = this;
      if (window.qg.getSystemInfoSync().platformVersionCode <= 1053) {
        console.log("快应用平台版本号低于1053，暂不支持banner API");
      } else {
        this.NativeID = e;
        console.log("创建原生广告，当前的广告ID: ", e);
        if (!this.NativeAds.has(e)) {
          var _t72 = window.qg.createNativeAd({
            posId: this.NativeID
          });
          _t72.onLoad(function (t) {
            console.log("原生广告加载完成-onload触发", JSON.stringify(t));
            if (t && t.adList) {
              console.log("adList", t.adList);
              var _n74 = $2ObjUtil.default.clonJson(t.adList.pop());
              _n74.nativeId = e;
              _this148.adMessage.set(e, _n74);
              _this148.nativeShowList.set(e, false);
              console.log("原生广告加载成功,下发消息", _n74);
              _this148.sendMsg(e, _n74);
            }
          });
          _t72.onError(function (e) {
            console.log("原生广告加载失败", e);
          });
          this.NativeAds.set(this.NativeID, _t72);
        }
        this.NativeAds.get(this.NativeID).load().then(function () {}).catch(function (n) {
          console.log("load错误：  ", JSON.stringify(n));
          t.getComponent("ComNativeView").init(_ctor.Instance.getMsg(e));
        });
      }
    }
  }, {
    key: "reportAdShow",
    value: function reportAdShow(e) {
      console.log("上报广告曝光", this.adMessage.get(e));
      return false === this.nativeShowList.get(e) && (this.nativeShowList.set(e, true), console.log("上报成功", e, this.adMessage.get(e).adId), this.NativeAds.get(e).reportAdShow({
        adId: this.adMessage.get(e).adId.toString()
      }), true);
    }
  }, {
    key: "nativeIsShow",
    value: function nativeIsShow(e) {
      return this.nativeShowList.get(e);
    }
  }, {
    key: "ClickAD",
    value: function ClickAD(e) {
      console.log("ClickAD", e);
      if (this.NativeAds.get(e) && this.adMessage.get(e)) {
        console.log("上报点击");
        this.NativeAds.get(e).reportAdClick({
          adId: this.adMessage.get(e).adId.toString()
        });
      } else {
        console.log("广告已销毁");
      }
    }
  }, {
    key: "Destroy",
    value: function Destroy(e) {}
  }], [{
    key: "Instance",
    get() {
      _ctor._instance || (_ctor._instance = new _ctor());
      return _ctor._instance;
    }
  }]);
}();
exports.default = def_VIVO_NativeAdMgr;